<?php


namespace app\common\business;


class Node
{
    protected ?\app\common\model\Node $model = null;

    public function __construct()
    {
        $this->model = new \app\common\model\Node();
    }

    public function getExists(int $isWholeHospital, int $nodeId, array $deptIds, array $conditionExtend = [])
    {
        $condition[] = ["node_id", "=", $nodeId];
        $condition[] = ["is_whole_hospital", "=", $isWholeHospital];
        if ($isWholeHospital === 0) {
            $arr = array_column($deptIds, "dept_id");
            $condition[] = ["apply_dept.dept_id", 'in', $arr];
        }
        $condition = array_merge($condition, $conditionExtend);

        return $this->model->where($condition)->find();
    }


    public function createData(array $data): bool
    {
        return $this->model->save($data);
    }

    public function getInfo(string $id)
    {
        return $this->model->where("id", "=", $id)->find();
    }

    public function getList(): \think\Paginator
    {
        return $this->model->getLists();
    }
}